package com.chen;

/**
 * join 方法可以让线程顺序执行,本质上是阻塞当前进程(本案例的main进程),直到被启动的进程执行完毕
 *
 */
class thread1 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("线程1：" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        }
    }

class thread2 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("线程2：" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class thread3 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("线程3：" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}


public class DemoJoin {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new thread1());
        Thread t2 = new Thread(new thread2());
        Thread t3 = new Thread(new thread3());
       t1.start();
       t1.join();
       t2.start();
       t3.start();
    }

}
